#!/usr/bin/env python
# coding:utf-8
'''
本模块是为了实现查看学生成绩
'''
from function import cursor,cat_grade,GUI,sort_sub
def check_grade():
    while True:
        try:
            print '''
    1、查看全部学生成绩
    2、查看指定学生成绩
    3、各科成绩排名
    4、返回
'''
            selcet = input('请输入（1-4）：')
            if selcet == 1:
                 cat_grade()
            elif selcet == 2:
                stu_num = input('请输入该学生的学号：')
                has_stu = cursor.execute('SELECT id FROM studata WHERE id = %d' % stu_num)
                if has_stu:
                    cursor.execute('SELECT id, name, chinese, math, english FROM studata WHERE id=%d' % stu_num)
                    stu_cat = cursor.fetchall()[0]
                    print GUI
                    print '| %-8d|%-8s | %-8d| %-8d| %d' \
                        % (stu_cat[0], stu_cat[1], stu_cat[2], stu_cat[3], stu_cat[4])
                    break
                else:
                    print '查无此人！！！'
            elif selcet == 3:
                sort_sub()
            elif selcet == 4:
                break
            else:
                print '请输入正确的选项'

        except (TypeError, EOFError, NameError, IOError, SyntaxError, ValueError):
            print '输入有误，请重新输入'